package com.situ.mall.controller;

import java.util.List;

import javax.servlet.http.HttpSession;

import com.situ.mall.pojo.entity.Order;
import com.situ.mall.pojo.entity.Shipping;
import com.situ.mall.pojo.entity.User;
import com.situ.mall.pojo.vo.CartVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.situ.mall.service.ICartService;
import com.situ.mall.service.IOrderService;
import com.situ.mall.service.IShippingService;
import com.situ.mall.common.util.JSONResult;

@Controller
@RequestMapping("/order")
public class OrderController {
	@Autowired
	private IOrderService orderService;
	@Autowired
	private IShippingService shippingService;
	@Autowired
	private ICartService cartService;

	
	@RequestMapping("/getConfirmOrderPage")
	public String getConfirmOrderPage(HttpSession session, Model model) {
		User user = (User) session.getAttribute("user");
		List<Shipping> shippingList = shippingService.selectByUserId(user.getId());
		model.addAttribute("shippingList", shippingList);
		
		List<CartVO> cartVOList = cartService.selectByUserIdAndChecked(user.getId());
		model.addAttribute("cartVOList", cartVOList);
		
		return "confirm_order";
	}
	
	@RequestMapping("/insert")
	@ResponseBody
	public JSONResult insert(Order order, HttpSession session) {
		User user = (User) session.getAttribute("user");
		order.setUserId(user.getId());
		orderService.insert(order);
		return JSONResult.ok("插入成功");
	}
	
	@RequestMapping("getOrderListPage")
	public String getOrderListPage() {
		
		return "order_list";
	}
	
	public static void main(String[] args) {
		System.out.println(0.1+0.2);
	}
}
